// pages/center/order/ordershow/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderInfo: [],
    orderType: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  updateStatus: function () {
    wx.showModal({
      title: '待完善',
      content: '此功能攻城狮正在努力添加',
      showCancel: false
    })
  },
  cancleOrder: function () {
    let _this = this;
    wx.showModal({
      title: '提示',
      content: '您将要取消订单嘛？',
      success: function (res) {
        if (res.cancel) {
          //点击取消,默认隐藏弹框
        } else {
          let orderID = _this.data.orderInfo.id;
          wx.request({
            url: getApp().globalData.requestUrl + '5c8379fddc4fe',
            data: { status: "cancle_order", order_id: orderID },
            header: { version: "v3.0" },
            method: 'POST',
            dataType: 'json',
            responseType: 'text',
            success: function (res) {
              _this.requestByOrderID(orderID);
            }
          })
        }
      }
    })
  },
  requestByOrderID: function (orderID) {
    wx.showLoading({
      title: '正在获取订单信息',
    })
    let ru = getApp().globalData.requestUrl + "5c7b647c47e7c";
    let _this = this;
    wx.request({
      url: ru,
      data: { order_id: orderID },
      header: { version: 'v3.0' },
      method: 'POST',
      dataType: 'json',
      responseType: 'text',
      success: function (res) {
        let oInfo = res.data.data.order;
        let oType = ""
        switch (oInfo.order_status) {
          case 0: oType = "已下单，等待商家接单"; break;
          case 1: oType = "商家已接单，后续状态待添加"; break;
          case -1: oType = "订单已关闭"; break;
          default: break;
        }
        _this.setData({
          orderInfo: oInfo,
          orderType: oType
        });
        wx.hideLoading();
      }
    })
  },
  goBack: function () {
    wx.switchTab({
      url: "/pages/cmmenu/index"
    })
  },
  onLoad: function (options) {
    wx.showLoading({
      title: '正在加载',
      mask: true,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
    let orderID = options.order_id;
    console.log('ordershow');
    console.log(options);
    this.requestByOrderID(orderID);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  }
})